<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
<script type="text/javascript" src="<%=contextPath %>/static/kindeditor/kindeditor-all-min.js"></script>
<script charset="utf-8" src="<%=contextPath %>/static/kindeditor/lang/zh-CN.js"></script>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t " id="signupForm" method="post"
			enctype="multipart/form-data">
			<input type="hidden" class="form-control" id="mainId" name="mainId" value="${recommendId }"/>
			<input type="hidden" class="form-control" id="companyId" name="companyId" value="${companyId }"/>
			<input type="hidden" class="form-control" id="communicateId" name="communicateId" value="${communicateId }"/>
			<div class="form-group">
				<label class="col-sm-3 control-label">推荐状态：</label>
				<div class="col-sm-8">
					<select class="form-control" name="status" id="status">
					    <option value="0">==请选择==</option>
						<c:forEach items="${fns:getDictList('rec_status')}"
							var="temp1">
							<c:if test="${temp1.value >9 }">
							<option value="${temp1.value }">${temp1.valueName }</option>
							</c:if>
						</c:forEach>
					</select>	
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">具体原因：</label>
				<div class="col-sm-8">
					<textarea rows="3" cols="3" id="results" name="results" class="form-control" style="width: 100%"></textarea>
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-3 control-label">对接人：</label>
				<div class="col-sm-8">
					<select class="form-control" id="contactId" name="contactId"> 
					 <option value="">==请选择==</option>
					</select>
				</div>
			</div>
			<div id="contactinfo" style="display: none;">
			<div class="form-group">
				<label class="col-sm-3 control-label">对接人：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="contactor" name="contactor" readonly="readonly"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">对接电话：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="phone" name="phone" readonly="readonly"/>
				</div>
			</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="remark" name="remark" />
				</div>
			</div>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-12">
					<button class="btn btn-primary" type="button" id="sub">提交</button>
				</div>
			</div>
		</form>
	</div>


	<script>
	KindEditor.ready(function(K){
		K.create('textarea[name="results"]', {
		themeType: 'simple',
		resizeType: 1,
		allowFileManager: true,
		items : [
			'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
			'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
			'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
		afterBlur: function(){this.sync();}
		});
		});
	var company_id = $("#companyId").val();
    $(function () {
        $("#sub").click(function () {
        	//批量验证表单非空
			//调用方式
        	var arr=new Array(
        	  new Array('results','推荐结果未填写!'),
        	  new Array('contactId','对接人未选择!')
        	)
        	  for(var i=0;i<arr.length;i++){
	        	  if($("#"+arr[i][0]).val()==''){
	        		  $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
	  		        });
	        		  $("#"+arr[i][0]).focus();
	  				return;
	  			}
        	  }
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/recommendResult/add',
				type : 'post',
				dataType : "json",
				beforeSend: function () {
			        // 禁用按钮防止重复提交
					$("#sub").attr("disabled","disabled");
					swal("信息已经提交，请等待后台处理~！");
			    },
				success : function(data) {
					if (data.code == 200) {
						swal({
							title : data.message,
							type : "success",
							showCancelButton : false,
							confirmButtonText : "确定",
							animation : "slide-from-bottom",
							text: "2秒后自动关闭。", 
	      	    			timer: 2000, 
							closeOnConfirm : true
						}, function() {
							top.Dialog.close();
						});
					} else {
						swal("错误", data.message, "error");
					}  
				},    
				complete: function () {
			        $("#sub").removeAttr("disabled");
			    },
			    error: function (data) {
			    	swal("错误", data.message, "error");
			    }
			});
		});
        $.ajax({
    		url: '<%=contextPath%>/company/getContactBy?companyId='+company_id,
			type : 'post',
			dataType : "json",
			success : function(data) {
				var htm='<option value="">==请选择==</option>';
				if(data.code==200){
					var result = data.contacts;
					for (var i = 0; i < result.length; i++) {
						htm +='<option value="'+result[i].contactId+'">'+result[i].resume.trueName+'/'+result[i].resume.cellphone+'</option>';
					}
				}
				$("#contactId").html(htm);
			}
    	});
       $("#contactId").change(function(){//查询市
   		var tid = $(this).val();
	       if(tid!=''){
	    	   $.ajax({
	    	 		url: '<%=contextPath%>/company/getcontactById?contactId='+tid+"&companyId="+company_id,
	    				type : 'post',
	    				dataType : "json",
	    				success : function(data) {
	    					if(data.code==200){
	    						var result = data.contact;
	    						$("#contactinfo").show();
	    						$("#contactor").val(result.resume.trueName);
	    						$("#phone").val(result.resume.cellphone);
	    					}else {
	    					  $("#contactinfo").hide();
							}
	    				}
	    	 	});
	       }
       });
	});
    
	</script>
</body>
</html>